<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Using the YouTube Data API - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.gdata.youtube.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.gdata.youtube.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.gdata.photos.html">Using Picasa Web Albums</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.gdata.youtube" class="section"><div class="info"><h1 class="title">Using the YouTube Data API</h1></div>
    

    <p class="para">
        The YouTube Data <acronym class="acronym">API</acronym> offers read and write access to YouTube&#039;s content.
        Users can perform unauthenticated requests to Google Data feeds to
        retrieve feeds of popular videos, comments, public information about
        YouTube user profiles, user playlists, favorites, subscriptions and so on.
    </p>

    <p class="para">
        For more information on the YouTube Data <acronym class="acronym">API</acronym>, please refer
        to the official <a href="http://code.google.com/apis/youtube/developers_guide_php.html" class="link external">&raquo; <acronym class="acronym">PHP</acronym>
            Developer&#039;s Guide</a> on code.google.com.
    </p>

    <div class="section" id="zend.gdata.youtube.authentication"><div class="info"><h1 class="title">Authentication</h1></div>
        

        <p class="para">
            The YouTube Data <acronym class="acronym">API</acronym> allows read-only access to public data, which
            does not require authentication. For any write requests, a user
            needs to authenticate either using ClientLogin or AuthSub authentication. Please refer
            to the <a href="http://code.google.com/apis/youtube/developers_guide_php.html#Authentication" class="link external">&raquo; Authentication
                section in the <acronym class="acronym">PHP</acronym> Developer&#039;s Guide</a> for more detail.
        </p>
    </div>

    <div class="section" id="zend.gdata.youtube.developer_key"><div class="info"><h1 class="title">Developer Keys and Client ID</h1></div>
        

        <p class="para">
            A developer key identifies the YouTube developer that is submitting
            an <acronym class="acronym">API</acronym> request. A client ID identifies your application for logging
            and debugging purposes. Please visit <a href="http://code.google.com/apis/youtube/dashboard/" class="link external">&raquo; http://code.google.com/apis/youtube/dashboard/</a>
            to obtain a developer key and client ID. The example below demonstrates how to pass the
            developer key and client ID to the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube.html" class="link external">&raquo; Zend_Gdata_YouTube</a>
            service object.
        </p>

        <div class="example" id="zend.gdata.youtube.developer_key.example"><div class="info"><p><b>Example #1 Passing a Developer Key and ClientID to Zend_Gdata_YouTube</b></p></div>
            

            <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube($httpClient,
                             $applicationId,
                             $clientId,
                             $developerKey);
</pre>

        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.videos"><div class="info"><h1 class="title">Retrieving public video feeds</h1></div>
        

        <p class="para">
            The YouTube Data <acronym class="acronym">API</acronym> provides numerous feeds that return a list of
            videos, such as standard feeds, related videos, video responses,
            user&#039;s uploads, and user&#039;s favorites. For example, the
            user&#039;s uploads feed returns all videos uploaded by a specific user. See the <a href="http://code.google.com/apis/youtube/reference.html#Video_Feeds" class="link external">&raquo; YouTube
                <acronym class="acronym">API</acronym> reference guide</a> for a detailed list of available
            feeds.
        </p>

        <div class="section" id="zend.gdata.youtube.videos.searching"><div class="info"><h1 class="title">Searching for videos by metadata</h1></div>
            

            <p class="para">
                You can retrieve a list of videos that match specified
                search criteria, using the YouTubeQuery class. The following query
                looks for videos which contain the word &quot;cat&quot; in their
                metadata, starting with the 10th video and displaying 20
                videos per page, ordered by the view count.
            </p>

            <div class="example" id="zend.gdata.youtube.videos.searching.example"><div class="info"><p><b>Example #2 Searching for videos</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$query = $yt-&gt;newVideoQuery();
$query-&gt;videoQuery = &#039;cat&#039;;
$query-&gt;startIndex = 10;
$query-&gt;maxResults = 20;
$query-&gt;orderBy = &#039;viewCount&#039;;

echo $query-&gt;queryUrl . &quot;\n&quot;;
$videoFeed = $yt-&gt;getVideoFeed($query);

foreach ($videoFeed as $videoEntry) {
    echo &quot;---------VIDEO----------\n&quot;;
    echo &quot;Title: &quot; . $videoEntry-&gt;getVideoTitle() . &quot;\n&quot;;
    echo &quot;\nDescription:\n&quot;;
    echo $videoEntry-&gt;getVideoDescription();
    echo &quot;\n\n\n&quot;;
}
</pre>

            </div>

            <p class="para">
                For more details on the different query parameters, please refer to the <a href="http://code.google.com/apis/youtube/reference.html#Searching_for_videos" class="link external">&raquo; 
                    Reference Guide</a>. The available helper functions in <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoQuery.html" class="link external">&raquo; <span class="classname">Zend_Gdata_YouTube_VideoQuery</span></a>
                for each of these parameters are described in more detail in the <a href="http://code.google.com/apis/youtube/developers_guide_php.html#SearchingVideos" class="link external">&raquo; PHP
                    Developer&#039;s Guide</a>.
            </p>
        </div>

        <div class="section" id="zend.gdata.youtube.videos.searchingcategories"><div class="info"><h1 class="title">Searching for videos by categories and tags/keywords</h1></div>
            

            <p class="para">
                Searching for videos in specific categories is done by generating a <a href="http://code.google.com/apis/youtube/reference.html#Category_search" class="link external">&raquo; specially
                    formatted <acronym class="acronym">URL</acronym></a>. For example, to search for
                comedy videos which contain the keyword dog:
            </p>

            <div class="example" id="zend.gdata.youtube.videos.searchingcategories.example"><div class="info"><p><b>Example #3 Searching for videos in specific categories</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$query = $yt-&gt;newVideoQuery();
$query-&gt;category = &#039;Comedy/dog&#039;;

echo $query-&gt;queryUrl . &quot;\n&quot;;
$videoFeed = $yt-&gt;getVideoFeed($query);
</pre>

            </div>
        </div>

        <div class="section" id="zend.gdata.youtube.videos.standard"><div class="info"><h1 class="title">Retrieving standard feeds</h1></div>
            

            <p class="para">
                The YouTube Data <acronym class="acronym">API</acronym> has a number of <a href="http://code.google.com/apis/youtube/reference.html#Standard_feeds" class="link external">&raquo; standard
                    feeds</a>. These standard feeds can be retrieved as <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoFeed.html" class="link external">&raquo; Zend_Gdata_YouTube_VideoFeed</a>
                objects using the specified <acronym class="acronym">URL</acronym>s, using the predefined constants
                within the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube.html" class="link external">&raquo; Zend_Gdata_YouTube</a>
                class (Zend_Gdata_YouTube::STANDARD_TOP_RATED_URI for example) or
                using the predefined helper methods (see code listing below).
            </p>

            <p class="para">
                To retrieve the top rated videos using the helper method:
            </p>

            <div class="example" id="zend.gdata.youtube.videos.standard.example-1"><div class="info"><p><b>Example #4 Retrieving a standard video feed</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt-&gt;getTopRatedVideoFeed();
</pre>

            </div>

            <p class="para">
                There are also query parameters to specify the time period
                over which the standard feed is computed.
            </p>

            <p class="para">
                For example, to retrieve the top rated videos for today:
            </p>

            <div class="example" id="zend.gdata.youtube.videos.standard.example-2"><div class="info"><p><b>Example #5 Using a Zend_Gdata_YouTube_VideoQuery to Retrieve Videos</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$query = $yt-&gt;newVideoQuery();
$query-&gt;setTime(&#039;today&#039;);
$videoFeed = $yt-&gt;getTopRatedVideoFeed($query);
</pre>

            </div>

            <p class="para">
                Alternatively, you could just retrieve the feed using the
                <acronym class="acronym">URL</acronym>:
            </p>

            <div class="example" id="zend.gdata.youtube.videos.standard.example-3"><div class="info"><p><b>Example #6 Retrieving a video feed by URL</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$url = &#039;http://gdata.youtube.com/feeds/standardfeeds/top_rated?time=today&#039;
$videoFeed = $yt-&gt;getVideoFeed($url);
</pre>

            </div>
        </div>

        <div class="section" id="zend.gdata.youtube.videos.user"><div class="info"><h1 class="title">Retrieving videos uploaded by a user</h1></div>
            

            <p class="para">
                You can retrieve a list of videos uploaded by a particular user
                using a simple helper method. This example retrieves videos
                uploaded by the user &#039;liz&#039;.
            </p>

            <div class="example" id="zend.gdata.youtube.videos.user.example"><div class="info"><p><b>Example #7 Retrieving videos uploaded by a specific user</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt-&gt;getUserUploads(&#039;liz&#039;);
</pre>

            </div>
        </div>

        <div class="section" id="zend.gdata.youtube.videos.favorites"><div class="info"><h1 class="title">Retrieving videos favorited by a user</h1></div>
            

            <p class="para">
                You can retrieve a list of a user&#039;s favorite videos
                using a simple helper method. This example retrieves videos
                favorited by the user &#039;liz&#039;.
            </p>

            <div class="example" id="zend.gdata.youtube.videos.favorites.example"><div class="info"><p><b>Example #8 Retrieving a user&#039;s favorite videos</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt-&gt;getUserFavorites(&#039;liz&#039;);
</pre>

            </div>
        </div>

        <div class="section" id="zend.gdata.youtube.videos.responses"><div class="info"><h1 class="title">Retrieving video responses for a video</h1></div>
            

            <p class="para">
                You can retrieve a list of a video&#039;s video responses
                using a simple helper method. This example retrieves video
                response for a video with the ID &#039;abc123813abc&#039;.
            </p>

            <div class="example" id="zend.gdata.youtube.videos.responses.example"><div class="info"><p><b>Example #9 Retrieving a feed of video responses</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt-&gt;getVideoResponseFeed(&#039;abc123813abc&#039;);
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.comments"><div class="info"><h1 class="title">Retrieving video comments</h1></div>
        

        <p class="para">
            The comments for each YouTube video can be retrieved in
            several ways. To retrieve the comments for the video with
            the ID &#039;abc123813abc&#039;, use the following code:
        </p>

        <div class="example" id="zend.gdata.youtube.videos.comments.example-1"><div class="info"><p><b>Example #10 Retrieving a feed of video comments from a video ID</b></p></div>
            

            <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$commentFeed = $yt-&gt;getVideoCommentFeed(&#039;abc123813abc&#039;);

foreach ($commentFeed as $commentEntry) {
    echo $commentEntry-&gt;title-&gt;text . &quot;\n&quot;;
    echo $commentEntry-&gt;content-&gt;text . &quot;\n\n\n&quot;;
}
</pre>

        </div>

        <p class="para">
            Comments can also be retrieved for a video if you have a copy of the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">&raquo; Zend_Gdata_YouTube_VideoEntry</a>
            object:
        </p>

        <div class="example" id="zend.gdata.youtube.videos.comments.example-2"><div class="info"><p><b>Example #11 Retrieving a Feed of Video Comments from a Zend_Gdata_YouTube_VideoEntry</b></p></div>
            

            <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$videoEntry = $yt-&gt;getVideoEntry(&#039;abc123813abc&#039;);
// we don&#039;t know the video ID in this example, but we do have the URL
$commentFeed = $yt-&gt;getVideoCommentFeed(null,
                                        $videoEntry-&gt;comments-&gt;href);
</pre>

        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.playlists"><div class="info"><h1 class="title">Retrieving playlist feeds</h1></div>
        

        <p class="para">
          The YouTube Data <acronym class="acronym">API</acronym> provides information about users, including
            profiles, playlists, subscriptions, and more.
        </p>

        <div class="section" id="zend.gdata.youtube.playlists.user"><div class="info"><h1 class="title">Retrieving the playlists of a user</h1></div>
            

            <p class="para">
                The library provides a helper method to retrieve
                the playlists associated with a given user. To retrieve the
                playlists for the user &#039;liz&#039;:
            </p>

            <div class="example" id="zend.gdata.youtube.playlists.user.example"><div class="info"><p><b>Example #12 Retrieving the playlists of a user</b></p></div>
                

                <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$playlistListFeed = $yt-&gt;getPlaylistListFeed(&#039;liz&#039;);

foreach ($playlistListFeed as $playlistEntry) {
    echo $playlistEntry-&gt;title-&gt;text . &quot;\n&quot;;
    echo $playlistEntry-&gt;description-&gt;text . &quot;\n&quot;;
    echo $playlistEntry-&gt;getPlaylistVideoFeedUrl() . &quot;\n\n\n&quot;;
}
</pre>

            </div>
        </div>

        <div class="section" id="zend.gdata.youtube.playlists.special"><div class="info"><h1 class="title">Retrieving a specific playlist</h1></div>
            

            <p class="para">
                The library provides a helper method to retrieve
                the videos associated with a given playlist. To retrieve the
                playlists for a specific playlist entry:
            </p>

            <div class="example" id="zend.gdata.youtube.playlists.special.example"><div class="info"><p><b>Example #13 Retrieving a specific playlist</b></p></div>
                

                <pre class="programlisting brush: php">
$feedUrl = $playlistEntry-&gt;getPlaylistVideoFeedUrl();
$playlistVideoFeed = $yt-&gt;getPlaylistVideoFeed($feedUrl);
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.subscriptions"><div class="info"><h1 class="title">Retrieving a list of a user&#039;s subscriptions</h1></div>
        

        <p class="para">
            A user can have several types of subscriptions: channel
            subscription, tag subscription, or favorites subscription. A <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_SubscriptionEntry.html" class="link external">&raquo; Zend_Gdata_YouTube_SubscriptionEntry</a>
            is used to represent individual subscriptions.
        </p>

        <p class="para">
            To retrieve all subscriptions for the user &#039;liz&#039;:
        </p>

        <div class="example" id="zend.gdata.youtube.subscriptions.example"><div class="info"><p><b>Example #14 Retrieving all subscriptions for a user</b></p></div>
            

            <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$subscriptionFeed = $yt-&gt;getSubscriptionFeed(&#039;liz&#039;);

foreach ($subscriptionFeed as $subscriptionEntry) {
    echo $subscriptionEntry-&gt;title-&gt;text . &quot;\n&quot;;
}
</pre>

        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.profile"><div class="info"><h1 class="title">Retrieving a user&#039;s profile</h1></div>
        

        <p class="para">
            You can retrieve the public profile information
            for any YouTube user. To retrieve the profile
            for the user &#039;liz&#039;:
        </p>

        <div class="example" id="zend.gdata.youtube.profile.example"><div class="info"><p><b>Example #15 Retrieving a user&#039;s profile</b></p></div>
            

            <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube();
$userProfile = $yt-&gt;getUserProfile(&#039;liz&#039;);
echo &quot;username: &quot; . $userProfile-&gt;username-&gt;text . &quot;\n&quot;;
echo &quot;age: &quot; . $userProfile-&gt;age-&gt;text . &quot;\n&quot;;
echo &quot;hometown: &quot; . $userProfile-&gt;hometown-&gt;text . &quot;\n&quot;;
</pre>

        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.uploads"><div class="info"><h1 class="title">Uploading Videos to YouTube</h1></div>
        

        <p class="para">
            Please make sure to review the diagrams in the <a href="http://code.google.com/apis/youtube/developers_guide_protocol.html#Process_Flows_for_Uploading_Videos" class="link external">&raquo; protocol
                guide</a> on code.google.com for a high-level
            overview of the upload process. Uploading videos can be done in one of
            two ways: either by uploading the video directly or by sending just the video
            meta-data and having a user upload the video through an <acronym class="acronym">HTML</acronym> form.
        </p>

        <p class="para">
            In order to upload a video directly, you must first construct a new <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">&raquo; Zend_Gdata_YouTube_VideoEntry</a>
            object and specify some required meta-data. The following example shows uploading the
            Quicktime video &quot;mytestmovie.mov&quot; to YouTube with the following properties:
        </p>

        <table id="zend.gdata.youtube.uploads.metadata" class="doctable table"><div class="info"><caption><b>Metadata used in the code-sample below</b></caption></div>
            

            
                <thead valign="middle">
                    <tr valign="middle">
                        <th>Property</th>
                        <th>Value</th>
                    </tr>

                </thead>


                <tbody valign="middle" class="tbody">
                    <tr valign="middle">
                        <td align="left">Title</td>
                        <td align="left">My Test Movie</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">Category</td>
                        <td align="left">Autos</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">Keywords</td>
                        <td align="left">cars, funny</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">Description</td>
                        <td align="left">My description</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">Filename</td>
                        <td align="left">mytestmovie.mov</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">File <acronym class="acronym">MIME</acronym> type</td>
                        <td align="left">video/quicktime</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">Video private?</td>
                        <td align="left"><b><tt>FALSE</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">Video location</td>
                        <td align="left">37, -122 (lat, long)</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">Developer Tags</td>
                        <td align="left">mydevelopertag, anotherdevelopertag</td>
                    </tr>

                </tbody>
            
        </table>


        <p class="para">
            The code below creates a blank <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">&raquo; Zend_Gdata_YouTube_VideoEntry</a>
            to be uploaded. A <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_App_MediaFileSource.html" class="link external">&raquo; Zend_Gdata_App_MediaFileSource</a>
            object is then used to hold the actual video file. Under the hood, the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_Extension_MediaGroup.html" class="link external">&raquo; Zend_Gdata_YouTube_Extension_MediaGroup</a>
            object is used to hold all of the video&#039;s meta-data. Our helper methods detailed below
            allow you to just set the video meta-data without having to worry about the media group
            object. The $uploadUrl is the location where the new entry gets posted to.
            This can be specified either with the $userName of the
            currently authenticated user, or, alternatively, you can simply use the
            string &#039;default&#039; to refer to the currently authenticated user.
        </p>

        <div class="example" id="zend.gdata.youtube.uploads.example"><div class="info"><p><b>Example #16 Uploading a video</b></p></div>
            

            <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube($httpClient);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$filesource = $yt-&gt;newMediaFileSource(&#039;mytestmovie.mov&#039;);
$filesource-&gt;setContentType(&#039;video/quicktime&#039;);
$filesource-&gt;setSlug(&#039;mytestmovie.mov&#039;);

$myVideoEntry-&gt;setMediaSource($filesource);

$myVideoEntry-&gt;setVideoTitle(&#039;My Test Movie&#039;);
$myVideoEntry-&gt;setVideoDescription(&#039;My Test Movie&#039;);
// Note that category must be a valid YouTube category !
$myVideoEntry-&gt;setVideoCategory(&#039;Comedy&#039;);

// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry-&gt;SetVideoTags(&#039;cars, funny&#039;);

// Optionally set some developer tags
$myVideoEntry-&gt;setVideoDeveloperTags(array(&#039;mydevelopertag&#039;,
                                           &#039;anotherdevelopertag&#039;));

// Optionally set the video&#039;s location
$yt-&gt;registerPackage(&#039;Zend_Gdata_Geo&#039;);
$yt-&gt;registerPackage(&#039;Zend_Gdata_Geo_Extension&#039;);
$where = $yt-&gt;newGeoRssWhere();
$position = $yt-&gt;newGmlPos(&#039;37.0 -122.0&#039;);
$where-&gt;point = $yt-&gt;newGmlPoint($position);
$myVideoEntry-&gt;setWhere($where);

// Upload URI for the currently authenticated user
$uploadUrl =
    &#039;http://uploads.gdata.youtube.com/feeds/users/default/uploads&#039;;

// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if availableor just a regular Zend_Gdata_App_Exception

try {
    $newEntry = $yt-&gt;insertEntry($myVideoEntry,
                                 $uploadUrl,
                                 &#039;Zend_Gdata_YouTube_VideoEntry&#039;);
} catch (Zend_Gdata_App_HttpException $httpException) {
    echo $httpException-&gt;getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
    echo $e-&gt;getMessage();
}
</pre>

        </div>

        <p class="para">
            To upload a video as private, simply use: $myVideoEntry-&gt;setVideoPrivate(); prior to
            performing the upload. $videoEntry-&gt;isVideoPrivate() can be used to check whether a
            video entry is private or not.
        </p>
    </div>

    <div class="section" id="zend.gdata.youtube.uploads.browser"><div class="info"><h1 class="title">Browser-based upload</h1></div>
        

        <p class="para">
            Browser-based uploading is performed almost identically to direct uploading,
            except that you do not attach a <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_App_MediaFileSource.html" class="link external">&raquo; Zend_Gdata_App_MediaFileSource</a>
            object to the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">&raquo; Zend_Gdata_YouTube_VideoEntry</a>
            you are constructing. Instead you simply submit all of your video&#039;s meta-data to receive
            back a token element which can be used to construct an <acronym class="acronym">HTML</acronym> upload
            form.
        </p>

        <div class="example" id="zend.gdata.youtube.uploads.browser.example-1"><div class="info"><p><b>Example #17 Browser-based upload</b></p></div>
            

            <pre class="programlisting brush: php">
$yt = new Zend_Gdata_YouTube($httpClient);

$myVideoEntry= new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry-&gt;setVideoTitle(&#039;My Test Movie&#039;);
$myVideoEntry-&gt;setVideoDescription(&#039;My Test Movie&#039;);

// Note that category must be a valid YouTube category
$myVideoEntry-&gt;setVideoCategory(&#039;Comedy&#039;);
$myVideoEntry-&gt;SetVideoTags(&#039;cars, funny&#039;);

$tokenHandlerUrl = &#039;http://gdata.youtube.com/action/GetUploadToken&#039;;
$tokenArray = $yt-&gt;getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray[&#039;token&#039;];
$postUrl = $tokenArray[&#039;url&#039;];
</pre>

        </div>

        <p class="para">
            The above code prints out a link and a token that is used to construct an
            <acronym class="acronym">HTML</acronym> form to display in the user&#039;s browser. A simple example form is
            shown below with $tokenValue representing the content of the returned token element,
            as shown being retrieved from $myVideoEntry above. In order for the user
            to be redirected to your website after submitting the form, make sure to
            append a $nextUrl parameter to the $postUrl above, which functions in the
            same way as the $next parameter of an AuthSub link. The only difference is
            that here, instead of a single-use token, a status and an id variable are
            returned in the <acronym class="acronym">URL</acronym>.
        </p>

        <div class="example" id="zend.gdata.youtube.uploads.browser.example-2"><div class="info"><p><b>Example #18 Browser-based upload: Creating the HTML form</b></p></div>
            

            <pre class="programlisting brush: php">
// place to redirect user after upload
$nextUrl = &#039;http://mysite.com/youtube_uploads&#039;;

$form = &#039;&lt;form action=&quot;&#039;. $postUrl .&#039;?nexturl=&#039;. $nextUrl .
        &#039;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;&#039;.
        &#039;&lt;input name=&quot;file&quot; type=&quot;file&quot;/&gt;&#039;.
        &#039;&lt;input name=&quot;token&quot; type=&quot;hidden&quot; value=&quot;&#039;. $tokenValue .&#039;&quot;/&gt;&#039;.
        &#039;&lt;input value=&quot;Upload Video File&quot; type=&quot;submit&quot; /&gt;&#039;.
        &#039;&lt;/form&gt;&#039;;
</pre>

        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.uploads.status"><div class="info"><h1 class="title">Checking upload status</h1></div>
        

        <p class="para">
            After uploading a video, it will immediately be visible in an
            authenticated user&#039;s uploads feed. However, it will not be public on
            the site until it has been processed. Videos that have been rejected or
            failed to upload successfully will also only be in the authenticated
            user&#039;s uploads feed. The following code checks the status of a <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">&raquo; Zend_Gdata_YouTube_VideoEntry</a>
            to see if it is not live yet or if it has been rejected.
        </p>

        <div class="example" id="zend.gdata.youtube.uploads.status.example"><div class="info"><p><b>Example #19 Checking video upload status</b></p></div>
            

            <pre class="programlisting brush: php">
try {
    $control = $videoEntry-&gt;getControl();
} catch (Zend_Gdata_App_Exception $e) {
    echo $e-&gt;getMessage();
}

if ($control instanceof Zend_Gdata_App_Extension_Control) {
    if ($control-&gt;getDraft() != null &amp;&amp;
        $control-&gt;getDraft()-&gt;getText() == &#039;yes&#039;) {
        $state = $videoEntry-&gt;getVideoState();

        if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
            print &#039;Upload status: &#039;
                  . $state-&gt;getName()
                  .&#039; &#039;. $state-&gt;getText();
        } else {
            print &#039;Not able to retrieve the video status information&#039;
                  .&#039; yet. &#039; . &quot;Please try again shortly.\n&quot;;
        }
    }
}
</pre>

        </div>
    </div>

    <div class="section" id="zend.gdata.youtube.other"><div class="info"><h1 class="title">Other Functions</h1></div>
        

        <p class="para">
            In addition to the functionality described above, the YouTube <acronym class="acronym">API</acronym>
            contains many other functions that allow you to modify video meta-data,
            delete video entries and use the full range of community features on the site. Some of
            the community features that can be modified through the <acronym class="acronym">API</acronym> include:
            ratings, comments, playlists, subscriptions, user profiles, contacts and messages.
        </p>
        <p class="para">
            Please refer to the full documentation available in the <a href="http://code.google.com/apis/youtube/developers_guide_php.html" class="link external">&raquo; PHP Developer&#039;s
                Guide</a> on code.google.com.
        </p>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.gdata.photos.html">Using Picasa Web Albums</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.gdata.html">Zend_Gdata</a></li>
  <li><a href="zend.gdata.introduction.html">Introduction</a></li>
  <li><a href="zend.gdata.authsub.html">Authenticating with AuthSub</a></li>
  <li><a href="zend.gdata.books.html">Using the Book Search Data API</a></li>
  <li><a href="zend.gdata.clientlogin.html">Authenticating with ClientLogin</a></li>
  <li><a href="zend.gdata.calendar.html">Using Google Calendar</a></li>
  <li><a href="zend.gdata.docs.html">Using Google Documents List Data API</a></li>
  <li><a href="zend.gdata.health.html">Using Google Health</a></li>
  <li><a href="zend.gdata.spreadsheets.html">Using Google Spreadsheets</a></li>
  <li><a href="zend.gdata.gapps.html">Using Google Apps Provisioning</a></li>
  <li><a href="zend.gdata.gbase.html">Using Google Base</a></li>
  <li><a href="zend.gdata.photos.html">Using Picasa Web Albums</a></li>
  <li class="active"><a href="zend.gdata.youtube.html">Using the YouTube Data API</a></li>
  <li><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>